package com.gjintel.business.webadv.service.Impl;

import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gjintel.business.webadv.dao.IWebAdvDao;
import com.gjintel.business.webadv.model.WebAdv;
import com.gjintel.business.webadv.service.IWebAdvService;
import com.gjintel.framework.util.DictUtil;
import com.gjintel.sdk.base.dao.Page;
import com.gjintel.sdk.base.dao.Sort;
import com.gjintel.sdk.base.service.impl.BaseServiceImpl;

@Service("WebAdvService")
public class WebAdvServiceImpl extends BaseServiceImpl implements IWebAdvService {
	@Autowired
	private IWebAdvDao webAdvDao;
	
	@Override
	public List<WebAdv> findAll() {
		return this.webAdvDao.findAll();
	}

	@SuppressWarnings("unchecked")
	@Override
	public void findAll(Page page, WebAdv adv, Sort sort) {
		this.webAdvDao.findAll(page, adv, sort);
		WebAdv temp = null;
		Iterator<WebAdv> webadvIt = page.getResult().iterator();
		WebAdv mdel = null;
		while (webadvIt.hasNext()) {
			temp = webadvIt.next();
			if (temp.getType() != null) {
				temp.setTypename(DictUtil.dict("adtype", temp.getType()).getName());
			}
			if (temp.getPosition() != null) {
				temp.setPositionname(DictUtil.dict("adposition", temp.getPosition()).getName());
			}
		}
	}

	@Override
	public void removeData(String deleteIds) throws Exception {
		WebAdv adv = null;
		for (String id : deleteIds.split(",")) {
			adv = this.get(WebAdv.class, id);
			if (adv != null) {
				adv.setFlag(1);
			}
		}
	}

}
